import os


def delete_csv_files_in_subdirectories(root_directory):
    """删除指定目录及其子目录中的所有 .csv 文件"""
    for root, dirs, files in os.walk(root_directory):
        for file in files:
            if file.endswith('.csv'):
                file_path = os.path.join(root, file)
                try:
                    os.remove(file_path)
                    print(f"已删除文件: {file_path}")
                except Exception as e:
                    print(f"删除文件时出错: {e}, 文件: {file_path}")


if __name__ == "__main__":
    # 指定要处理的根目录
    csv_root_directory = 'E:\\desk\\datawork\\csv'

    # 删除 CSV 文件
    delete_csv_files_in_subdirectories(csv_root_directory)